package com.ag.lwc.dao;

import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.classic.Session;

import com.ag.bean.TbPropose;
import com.ag.bean.TbProposeRecord;
import com.ag.dao.TbProposeDAO;
/**
 * 成批的dao
 * @author user
 *
 */
public class MyProposeDAO extends com.ag.dao.TbProposeDAO {
/**
 * 根据当前事件查询成批,同时初始化成批的成批日志
 * @param eventId		事件id
 * @return
 */
	public TbPropose findByEvent(String eventId)
	{
		TbPropose result=null;
		Session session = this.getSessionFactory().openSession();
		List<TbPropose> list = session.createSQLQuery("select * from TB_PROPOSE where TB_PROPOSE.E_ID =:eventId").addEntity(TbPropose.class).setString("eventId", eventId).list();
		//存在这条记录
		if(list!=null&&list.size()==1)
		{
			result = list.get(0);
			System.out.println("MyProposeDAO: id:"+result.getPpId()+"  成批类容："+result.getPaContent()+" 总指挥："+result.getTbUserByPCommander().getUName()+" 副总指挥："+result.getTbUserByPViceCommander().getUName()+" 工作组组长："+result.getTbUserByPTeamLeader().getUName()+" 实施应急部门 :"+result.getTbUserDeptByPImplementPlan().getUdName()+" 协助部门："+result.getTbUserDeptByPAssistDept().getUdName());
			for(TbProposeRecord record:result.getTbProposeRecords())
			{
				System.out.println("记录id："+record.getNewPpId()+" 审核人："+record.getTbUserByPrCheckId().getUName()+" 被审核人: "+record.getTbUserByPrId().getUName()+" 成批意见: "+record.getPComments()+" 总指挥："+record.getPCommander()+" 副总指挥："+record.getPViceCommander()+" 工控组组长: "+record.getPTeamLeader()+" 应急预案部门："+record.getPImplementPlan()+" 协助部门："+record.getPAssistDept()+" 审核时间："+record.getPaTime());
			}
			
		}
		
		session.close();
		return result;
	}
	/**
	 * 返回成批的记录
	 * @param pid成批记录id
	 * @return
	 */
	public List<TbProposeRecord> findProposeRecord(String pid)
	{
		List<TbProposeRecord> list =null;
		if(pid==null) return null;
		
		Session session = this.getSessionFactory().openSession();
		list = session.createSQLQuery("select * from TB_PROPOSE_RECORD where TB_PROPOSE_RECORD.PP_ID =:pid").addEntity(TbProposeRecord.class).setString("pid", pid).list();
		//存在这条记录
	//	list = session.createQuery("from TbProposeRecord left join fatch tbPropose").list();
		if(list!=null&&list.size()==1)
		{
			System.out.println("查了出来了");
			for(TbProposeRecord record:list)
			{
			//	Hibernate.initialize(record.getTbUserByPrCheckId());
			//	Hibernate.initialize(record.getTbUserByPrId());
			//	record.getTbUserByPrCheckId();
			//	record.getTbUserByPrId();
				System.out.println("记录id："+record.getNewPpId()+" 审核人："+record.getTbUserByPrCheckId().getUName()+" 被审核人: "+record.getTbUserByPrId().getUName()+" 成批意见: "+record.getPComments()+" 总指挥："+record.getPCommander()+" 副总指挥："+record.getPViceCommander()+" 工控组组长: "+record.getPTeamLeader()+" 应急预案部门："+record.getPImplementPlan()+" 协助部门："+record.getPAssistDept()+" 审核时间："+record.getPaTime());
			}
			
		}
		session.close();
		return list;
	}

}
